/*
 * R. J. Cano, 2017-03-21; Reviewed: 2017-03-24;
 * 
 *             Filename: sqrfreekalmostthings.txt
 * Programming Language: PARI-GP;
 * 
 *   Changes / Upgrades: Typos fixed, feedback improvements, and more detailed explanations.
 * 
 * Greetings!!!, May you have all, a nice and fruitful spring 2017...
 * 
 * Here is shwon briefly a humble experiment on the apparent connection
 * of the human readable languages (their writing) and the number theory
 * conceptions related to primality.
 * 
 * I hope you enjoy it.
 * 
 * Best regards,
 * 
 * R. J.
 * 

  What is all this code about?... 
 ---------------------------------
  
 [The one shown soon below] ( a.k.a "Current implementation pupose" ):
  
 Imagine some kind of Sieve like this: You had been instructed to pick some plane (2D) surface and by the account of some "Geometrical" pattern, you must divide its area in identical parts, squares, circles, ellipses, triangles... any of such possibilities, put by ignoring trailing surface area and by juxtaposition of the obtained "pieces" you assign the letters from some alphabet to each unit. You additionally must enumerate and rank them according to some convention gave to you as specification. (This was step zero)

Then, now you are also instructed to transliterate as long as it be possible, arbitrarily long texts wrote with the letters of the specified alphabet, guiding you through the transliteration by two simple principles:

1) If you find a symbol for which there is no coincidence there at the table you enthusiastic and patient built before in "step zero", then you assign it a "wildcard" for meaning wit it "unknown".

2) The order of transliteration is the same of reading for western languages... i.e. from left to right and from top to bottom. With such kind of linearization of assignation for ranking elements inside a matrix (your built table at s. zero!), you enumerate the indices for the transliterated characters (including the wildcard) turning all the information into the form of a single vector.

(This was step 1)

Well, now you construct a Mathematically meaningful information from it, this is, based upon the vector obtained after such particular "incomplete" transliteration of certain text. Aiming to operate these just introduced/proposed representations, in the hope of finding out their properties.

(This is roughly, the step 2)

Perhaps this is NOT quite an original procedure since it resembles (at least just a little bit) the calculation of an MD5 checksum (for example).

Finally (Alleluia!):
The program I stubbornly submitted you previously without enough "documentation"... (No Remy is perfect!), implements steps zero..2 including as mathematical representation, a polynomial analogous to the one required when interpreting unsigned integers in come positional number system, where by default the base 36 standard alphabet is assumed, and if [] is passed as the corresponding argument (please give another glance to the source code for "assignedValue"), then the smallest possible alphabet is constructed: By omitting repetitions and ranking from zero some permutation of the resulting letters.

That's all.

------------------------------------------------

Question and answers!

Q: "Hey dude!, why you talk initially about a Sieve?"
A: Indeed, a Sieve it is (would say the master Yoda from Star Wars); Please notice that every possible symbol from the arbitrary text to be transliterated, is NOT actually present at the assignation table. Not all of them are assignable. For such circumstance is included the "wildcard", therefore it represents the holes of such poetry term (Sieve).

Q: "Well, why you spent all these keystrokes and breath ... ?"
A: Please try to built "randomly" squarefree numbers starting from ( / based upon ) human readable/meaningful languages.

Q: "O.K., but which is your point, anyway?"
A: Ask Carl Pomerance (among others) about the value of being able to identify huge semi-primes... in principle, and for warming out just that.

   =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
       [SOURCE CODE PLUS EXECUTION SAMPLES STARTS]
   =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

*/


/* isRepunitVec(v)={my(u=sum(j=1,#v,v[j]==1)==#v);print1(u);u} */ \\ DEPRECATED

isRepunitVec(v)={!for(j=1,#v,v[j]==1||return)} \\ From: M. F. Hasler via e-mail On 2017-March-22th 12:49 UTC/GMT (Danke meister!)

filterAndLowerCaseOnly(w)={my(m=Vec(w),g=Vec("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"),a=vector(#w),k);for(i=1,#w,k=vecsearch(g,m[i]);k+=(k<27)*26*!!k;if(k,a[i]=g[k],a[i]=m[i]));a}

alphabet(w)=vecsort(filterAndLowerCaseOnly(w),,8);

assignedValue(w,{B=10},{s0=Vec("0123456789abcdefghijklmnopqrstuvwxyz")},{R=0})={my(s=if(s0==[],alphabet(w),s0),x=filterAndLowerCaseOnly(w));B=min(max(2,B),#s);if(!!R,x=Vecrev(x));sum(j=1,#x,(vecsearch(s,x[j])-1)*(B^(#x-j)))}

/*
        ------------------------------------------------------------------------------
   ========================= Some examples of execution [Begin] ========================= 
   
REMARK: Some invocation parameter combinations are NOT exactly numbers (in a given base)
        although they all are in common polynomials instead;
   
? #
   timer = 1 (on)

? assignedValue("FF",16)
%result = 255

\\ ...Explanation: Just-in-case of a "Je ne sais qui" lagoon ---> https://en.wikipedia.org/wiki/Hexadecimal ( ;-D My sincere apologizes for PhD'd redaers)

? assignedValue("FF",[])
%result = 0

\\ ...Explanation: If the alphabet must be built upon "FF" there is only an unique repeated letter, corresponding to zero (the first digit of any alphabet!);

\\ These calculations become curious and interesting:

? factor(assignedValue("JoergArndt",10,[]))
%result = 
[      67 1]

[27185537 1]

? factor(assignedValue("JoergArndt",10,))
%result = 
[21568729459 1]

\\ Notice these two below...

? assignedValue("JoergArndt",10,[]) 
%result = 1821430979

? assignedValue("Joerg Arndt",10)
time = 1 ms.
%result = 215686029459

\\ Why they differ?, simply because the "white space" character is absent there at the default alphabet, so vecsearch returns 0 and the effect
\\ (please see the definition above) is to subtract the corresponding power of the base (specified by B, with 2 <= B <= #alphabet).

\\ Another additional subtlety: 

? assignedValue("Joerg Arndt",10) \\ Notice it is NOT exaclty the same than the previous call.
time = 1 ms.
%result = 215686028559

\\ Indeed! they differ in absolute value the same than: 9459 - 8559 = 900; Nothing to be surprised by having into account A215940.

\\ But they have both "somewhat similar" prime factorizations anyway... 

? factor(215686028559)
time = 1 ms.

%result = 
[        3 1]

[      313 1]

[229697581 1]

? factor(215686029459)
time = 1 ms.

%result = 
[        3 1]

[      443 1]

[162291971 1]

? assignedValue("Joerg Arndt",10,[]) 
%result = 57384018629

? factor(%)
%result =  
[         7 2]

[1171102421 1]


? alphabet("Joerg Arndt")
time = 1 ms.
%result = [" ", "a", "d", "e", "g", "j", "n", "o", "r", "t"]

? prod(k=2,36,isRepunitVec(factor(assignedValue("Joerg Arndt",k))[,2]~))
11101111111101111110101111111101111
time = 15 ms.

\\ By manually copy/paste of such resulting bits pattern:

? factor(assignedValue("11101111111101111110101111111101111",2,["0","1"]))
time = 1 ms.

%result = 
[    31 1]

[  5501 1]

[188869 1]

%result = 0
? prod(k=2,36,isRepunitVec(factor(assignedValue("Joerg Arndt",k,[]))[,2]~))
10101110000000000000000000000000000
time = 10 ms.

%result = 0

? factor(assignedValue("10101110000000000000000000000000000",2,["0","1"]))
time = 4 ms.

%result = 
[ 2 28]

[ 3  1]

[29  1]

? prod(k=2,36,isRepunitVec(factor(assignedValue("squarefree k-almost prime",k))[,2]~)) 
10001011101010111011001110101011101
time = 3,193 ms.
%result = 0

? factor(assignedValue("10001011101010111011001110101011101",2,["0","1"]))
%result = 
[         5 1]

[3749257081 1]

? assignedValue(   "JensKruseAndersen"        ,36)
time = 3 ms.
%result = 154455712358375134979676815

? factor(%)
time = 22 ms.
%result = 
[             5 1]

[  381727279723 1]

[80924639428681 1]

? assignedValue(   "JensKruseAndersen"        ,36,,1)
%result = 186320860627093237643683195

? factor(%)
time = 2 ms.
%result =
[                      5 1]

[                     11 1]

[                    269 1]

[12593501901121543605521 1]

? assignedValue(   "Jens Kruse Andersen"        ,36,,1)
time = 7 ms.
%result = 241471835372656566377805890683

? factor(%)
time = 23 ms.
%result = 
[                      8969 1]

[26922938496226621293099107 1]

? assignedValue(   "Jens Kruse Andersen"        ,36,,0)
%result = 200174473048695197843186834063

? factor(%)
time = 5 ms.
%result = 
[    16447 1]

[    25763 1]

[    42577 1]

[ 36428209 1]

[304587931 1]

? 

\\ An squarefree farewell (of course, for now!)

? assignedValue(   "If you wish, you can mail me to: 0xcc00ffffeeee@gmail.com"        ,36)

time = 1 ms.
%result = 26190899156431758809526495006606737721918559628455382783637864169072957762615163756046070

? factor(%)

time = 20 ms.
%result = 
[2 1]

[5 1]

[149 1]

[1327 1]

[13246258228143290770181766919683970869306332408700749424011300743501240504450753709 1]

? quit
Goodbye!
bash-4.3$ 

   ========================= Some examples of execution [ End ] ========================= 
        ------------------------------------------------------------------------------

   =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        [SOURCE CODE PLUS EXECUTION SAMPLES ENDS]
   =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        
EOF*/